package com.ktjy.crm.service.impl;

import com.ktjy.crm.entity.SysUser;
import com.ktjy.crm.mapper.UserMapper;
import com.ktjy.crm.service.SysUserservice;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description
 * @Author 曹正
 * @Date 2025/1/3 20:29
 **/
@Service()
public class SysUserserviceImpl implements SysUserservice {
    @Resource
    public UserMapper userMapper;

    @Override
    public SysUser login(String account, String password) {
        SysUser user=userMapper.getUserByUserNameWithRoleName(account);
        if (user!=null){
            if (user.getUsrPassword().equals(password)){
                return user;
            }
        }
        return null;
    }

    @Override
    public int addUser(SysUser sysUser) {
        return userMapper.insert(sysUser);
    }

    @Override
    public int deleteUser(int id) {
        return userMapper.delete(id);
    }

    @Override
    public int updateUser(SysUser sysUser) {
        return userMapper.update(sysUser);
    }

    @Override
    public SysUser getUser(int id) {
        return userMapper.selectById(id);
    }

    @Override
    public List<SysUser> findAllUsers() {
        return userMapper.getUserListWithRoleName();
    }
}
